<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 拷贝继承：把一个对象中的属性或者方法直接复制到另一个对象中，

        // var obj1 = {
        //     name:'小糊涂',
        //     age:20,
        //     sleep:function(){
        //         console.log('sleepping')
        //     }
        // }

        // var obj2 = obj1; //改变地址的指向
        // console.log(obj2.name,obj2.age)
        // obj2.sleep()
            

        //拷贝继承
        function Person(){

        }
        Person.prototype.age = 10;
        Person.prototype.sex = '男';
        Person.prototype.height = 100;
        Person.prototype.play = function(){
            console.log('玩的好开心')
        }

        var obj2 = {};
        //Person 构造中有原型prototype,prototype就是一个对象，那么里面的age，sex，height，play就是该对象中的属性或方法

        for (const key in Person.prototype) {
            if (!obj2.hasOwnProperty(key)) {
                const element = Person.prototype[key];
                obj2[key] = element                
            }
        }
        console.dir(obj2)
        obj2.play()



    </script>
</body>
</html>